package com.douqu.game.core.config.sprite;

import com.douqu.game.core.e.E_Attribute;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.i.IGetExtraAddAttribute;
import com.douqu.game.core.util.LogUtils;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-10-16 19:52
 */
public class Sprite extends SpriteAttribute {

    public String deathAudio;

    public int quality;

    public String model;

    public String avatar;

    public int modelSizeGrade;

    /**
     * 类型
     * 1。地面
     * 2。飞行
     */
    public int unitType;

    /**
     * 阵营
     * 1.联盟
     * 2.部落
     * 3.天灾
     */
    public int camp;

    /**
     * 职业
     */
    public int profession;

    /** 攻击成长 */
    public float atkGrow;
    /** 防御成长 */
    public float defGrow;
    /** 生命成长 */
    public float hpGrow;
    /** 力量成长 */
    public float powerGrow;
    /** 敏捷成长 */
    public float agilityGrow;
    /** 智力成长 */
    public float wisdomGrow;
    /** 物理抗成长 */
    public float phyResGrow;
    /** 穿刺抗成长 */
    public float punResGrow;
    /** 魔法抗成长 */
    public float magResGrow;

    /**
     * 移动速度(每秒移动多少米)
     */
    public int moveSpeed;

    /**
     * 占位几格 1*1 2*2
     */
    public int gridArea = 1;




    public Sprite()
    {

    }





    /**
     * 获取星级属性
     * @param attrId
     * @param star
     * @return
     */
    public int getStarAttribute(int attrId, int star)
    {
        //子类实现
        return 0;
    }

    public int getLevelPlus(int attrId, int lv)
    {
        if(attrId == E_Attribute.ATK.getCode())
            return (int) ((lv - 1) * atkGrow);

        if(attrId == E_Attribute.DEF.getCode())
            return (int) ((lv - 1) * defGrow);

        if(attrId == E_Attribute.HP.getCode())
            return (int) ((lv - 1) * hpGrow);

        if(attrId == E_Attribute.POWER.getCode())
            return (int) ((lv - 1) * powerGrow);

        if(attrId == E_Attribute.AGILITY.getCode())
            return (int) ((lv - 1) * agilityGrow);

        if(attrId == E_Attribute.WISDOM.getCode())
            return (int) ((lv - 1) * wisdomGrow);

        if(attrId == E_Attribute.PHY_RES.getCode())
            return (int) ((lv - 1) * phyResGrow);

        if(attrId == E_Attribute.PUN_RES.getCode())
            return (int) ((lv - 1) * punResGrow);

        if(attrId == E_Attribute.MAG_RES.getCode())
            return (int) ((lv - 1) * magResGrow);

        E_Attribute attribute = E_Attribute.forNumber(attrId);
        if(attribute == null)
            return 0;

        return 0;
    }

    /**
     * 获取属性增加
     * @param attrId
     * @return
     */
    public int getAttribute(int attrId, int lv, int extraValue)
    {
        if(attrId == E_Attribute.ATK.getCode())
            return (int) (atk + extraValue + (lv - 1) * atkGrow);

        if(attrId == E_Attribute.DEF.getCode())
            return (int) (def + extraValue +(lv - 1) * defGrow);

        if(attrId == E_Attribute.HP.getCode())
            return (int) (hp + extraValue +(lv - 1) * hpGrow);

        if(attrId == E_Attribute.POWER.getCode())
            return (int) (power + extraValue +(lv - 1) * powerGrow);

        if(attrId == E_Attribute.AGILITY.getCode())
            return (int) (agility + extraValue +(lv - 1) * agilityGrow);

        if(attrId == E_Attribute.WISDOM.getCode())
            return (int) (wisdom + extraValue +(lv - 1) * wisdomGrow);

        if(attrId == E_Attribute.PHY_RES.getCode())
            return (int) (phyRes + extraValue +(lv - 1) * phyResGrow);

        if(attrId == E_Attribute.PUN_RES.getCode())
            return (int) (punRes + extraValue +(lv - 1) * punResGrow);

        if(attrId == E_Attribute.MAG_RES.getCode())
            return (int) (magRes + extraValue +(lv - 1) * magResGrow);

        E_Attribute attribute = E_Attribute.forNumber(attrId);
        if(attribute == null)
            return 0;

        return Integer.parseInt(getVariable(attribute.getMsg())) + extraValue;
    }

    /**
     * 获取战力
     * @return
     */
    public int getFC(int lv, IGetExtraAddAttribute iGetAttribute)
    {
//        return (int) (getAttribute(E_Attribute.HP.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.HP.getCode())) * 0.05
//                    + getAttribute(E_Attribute.ATK.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.ATK.getCode()))
//                    + getAttribute(E_Attribute.DEF.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.DEF.getCode()))
//                    +(getAttribute(E_Attribute.CRI.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.CRI.getCode()))
//                    + getAttribute(E_Attribute.REC.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.REC.getCode()))
//                    + getAttribute(E_Attribute.ADD.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.ADD.getCode()))
//                    + getAttribute(E_Attribute.EXD.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.EXD.getCode()))
//                    + getAttribute(E_Attribute.HIT.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.HIT.getCode()))
//                    + getAttribute(E_Attribute.EVA.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.EVA.getCode()))) * 0.5
//                    +(getAttribute(E_Attribute.POWER.getCode(),   lv, iGetAttribute.getAttributeValue(E_Attribute.POWER.getCode()))
//                    + getAttribute(E_Attribute.PHY_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.PHY_RES.getCode()))
//                    + getAttribute(E_Attribute.AGILITY.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.AGILITY.getCode()))
//                    + getAttribute(E_Attribute.PUN_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.PUN_RES.getCode()))
//                    + getAttribute(E_Attribute.WISDOM.getCode(),  lv, iGetAttribute.getAttributeValue(E_Attribute.WISDOM.getCode()))
//                    + getAttribute(E_Attribute.MAG_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.MAG_RES.getCode()))) * 5);

        //20180810 后面6个属性的乘系数由0.5修改为1
        return (int) (getAttribute(E_Attribute.HP.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.HP.getCode())) * 0.05
                + getAttribute(E_Attribute.ATK.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.ATK.getCode()))
                + getAttribute(E_Attribute.DEF.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.DEF.getCode()))
                +(getAttribute(E_Attribute.CRI.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.CRI.getCode()))
                + getAttribute(E_Attribute.REC.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.REC.getCode()))
                + getAttribute(E_Attribute.ADD.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.ADD.getCode()))
                + getAttribute(E_Attribute.EXD.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.EXD.getCode()))
                + getAttribute(E_Attribute.HIT.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.HIT.getCode()))
                + getAttribute(E_Attribute.EVA.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.EVA.getCode())))//这里原来是乘0.5,修改为1
                +(getAttribute(E_Attribute.POWER.getCode(),   lv, iGetAttribute.getAttributeValue(E_Attribute.POWER.getCode()))
                + getAttribute(E_Attribute.PHY_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.PHY_RES.getCode()))
                + getAttribute(E_Attribute.AGILITY.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.AGILITY.getCode()))
                + getAttribute(E_Attribute.PUN_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.PUN_RES.getCode()))
                + getAttribute(E_Attribute.WISDOM.getCode(),  lv, iGetAttribute.getAttributeValue(E_Attribute.WISDOM.getCode()))
                + getAttribute(E_Attribute.MAG_RES.getCode(), lv, iGetAttribute.getAttributeValue(E_Attribute.MAG_RES.getCode()))) * 10);
    }





    /**
     * 是否能克制对方
     * @param target
     * @return
     */
    public boolean isRestrict(Sprite target)
    {
        return false;
    }

    /**
     * 是否跟对方克制关系一样
     * @param target
     * @return
     */
    public boolean isSameRestrict(Sprite target)
    {
        return false;
    }




    @Override
    public boolean setVariable(String key, String value)
    {
        if("profession".equals(key))
        {
            profession = Integer.parseInt(value);
            if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.PROFESSION_KEY, profession) == null)
            {
                LogUtils.error("Load Sprite profession is null, profession = " + value);
                return false;
            }
            return true;
        }
        else
            return super.setVariable(key, value);
    }


    @Override
    public String toString() {
        return "Sprite{" +
                "camp=" + camp +
                ", profession=" + profession +
                ", moveSpeed=" + moveSpeed +
                "} " + super.toString();
    }
}
